<?php
/**
 * Created by PhpStorm.
 * User: dingboxu
 * Date: 17/2/21
 * Time: 下午5:07
 */

use Workerman\Protocols\Http;
use \Workerman\Autoloader;

require_once __DIR__ . '/../../Workerman/Autoloader.php';

require_once __DIR__.'/Config/Const.php';

Autoloader::setRootPath(__DIR__);




// 获取前台传入的数据
$handle = fopen ( 'php://input', 'r' );
$json = fgets ( $handle );
$data_arr = json_decode ( $json, true );

//
//    // 行为日志记录
//    Util_log::action_log(__FILE__, '001', $action_type);
//    //调式日志
//    Util_log::debug(__FILE__, 'DEBUG');
//    //错误日志
//    Util_log::error(__FILE__, 'ERR');


$dataDictionary = $data_arr[DATA_DICTIONARY];

if (array_key_exists(REQUEST_ID,$data_arr)) {
    $requestId = $data_arr[REQUEST_ID];
} else {
    $requestId = 0;
}

\Workerman\Protocols\Http::header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
\Workerman\Protocols\Http::header("Access-Control-Allow-Credentials:true");

Http::sessionStart();

switch($data_arr[SYS_EVENT]) {

    case EVENT_SPECIES_LIST:
        // 首页获取花木品种列表
        new \ActionsHttp\SpeciesList(EVENT_SPECIES_LIST,$requestId,$dataDictionary,$connection);
        break;

    case EVENT_GOURP_LIST:
        // 获取花木品种分组列表
        new \ActionsHttp\GroupList(EVENT_GOURP_LIST,$requestId,$dataDictionary,$connection);
        break;
//
//        case EVENT_PRODUCTOR_LIST:
//            // 获取分组内花木品种例表
//            new \ActionsHttp\ProductorList(EVENT_PRODUCTOR_LIST,$requestId,$dataDictionary,$connection);
//            break;

    case EVENT_PRODUCTOR_INFO:
        // 获取分组内花木品种信息
        new \ActionsHttp\ProductorInfo(EVENT_PRODUCTOR_INFO,$requestId,$dataDictionary,$connection);
        break;


    case EVENT_CUSTOMER_LOGIN_BY_PHONE_NUMBER:
        // 用户手机号登录+注册
        new \ActionsHttp\CustomerLoginByPhoneNumber(EVENT_CUSTOMER_LOGIN_BY_PHONE_NUMBER,$requestId,$dataDictionary,$connection);
        break;

    case EVENT_CUSTOMER_LOGIN_BY_WX:
        // 微信登录/注册
        new \ActionsHttp\CustomerLoginByWx(EVENT_CUSTOMER_LOGIN_BY_WX,$requestId,$dataDictionary,$connection,false);
        break;

    case EVENT_VERIFY_CODE_GET:
        // 获取验证码
        new \ActionsHttp\VerifyCodeGet(EVENT_VERIFY_CODE_GET,$requestId,$dataDictionary,$connection,false);
        break;

    case EVENT_QUESTION_ADD:
        // 问题反馈
        new \ActionsHttp\QuestionAdd(EVENT_QUESTION_ADD,$requestId,$dataDictionary,$connection);
        break;

    case EVENT_QUESTION_LIST:
        // 问题反馈列表
        new \ActionsHttp\QuestionList(EVENT_QUESTION_LIST,$requestId,$dataDictionary,$connection);
        break;

    case EVENT_PRODUCTOR_INFO_HIST:
        // 产品历史价格列表
        new \ActionsHttp\ProductorInfoHist(EVENT_PRODUCTOR_INFO_HIST,$requestId,$dataDictionary,$connection);
        break;

    case EVENT_CUSTOMER_LOGOUT:
        // 退出登录
        new \ActionsHttp\CustomerLogout(EVENT_CUSTOMER_LOGOUT,$requestId,$dataDictionary,$connection);
        break;

    case EVENT_LOGIN_STATE:
        // 是否还在登录有效期内
        new \ActionsHttp\CustomerLoginState(EVENT_LOGIN_STATE,$requestId,$dataDictionary,$connection);
        break;





    default:
        echo \Actions\ActionUtils::getResponseData(array(),$data_arr[SYS_EVENT],$requestId,RESULT_CODE_NOT_FOUND,"没有找到该通讯");
        break;

}
